<!--
 * @Author: windys
 * @Description: 
 * @Date: 2022-02-14 15:52:30
-->
<template>
  <div class="article_page">
    <!-- <van-sticky> -->
    <!-- <van-nav-bar title="热门课程">
        <template #right>
          <div class="nav_right" @click="handleHome">
            <van-icon name="manager" style="color: #fff" />
          </div>
        </template>
      </van-nav-bar> -->

    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item>
        <img
          src="http://vod.caihuapp.com/image/default/1070E86B24664EDE87823E8E8A630C43-6-2.jpeg"
          alt=""
          srcset=""
        />
      </van-swipe-item>
      <van-swipe-item>
        <img
          src="http://vod.caihuapp.com/image/default/F43C5758FF6543DF9C0BA52DCA7A8DC5-6-2.jpg"
          alt=""
          srcset=""
        />
      </van-swipe-item>
      <van-swipe-item>
        <img
          src="http://vod.caihuapp.com/image/default/71FF1E8B4864481DBFACAAC726FBCEBC-6-2.jpg"
          alt=""
          srcset=""
        />
      </van-swipe-item>
      <van-swipe-item>
        <img
          src="http://vod.caihuapp.com/image/default/0708DC17001B443DAC3A2E3D1522E992-6-2.jpg"
          alt=""
          srcset=""
        />
      </van-swipe-item>
    </van-swipe>
    <!-- </van-sticky> -->

    <div class="list">
      <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div
          class="list_item"
          v-for="(item, index) in list"
          :key="index"
          @click="handleClick(item)"
        >
          <div class="left">
            <van-image
              width="120"
              height="100"
              radius="5"
              :src="item.courseUrl"
            />
          </div>
          <div class="right">
            <div class="name">{{ item.courseName }}</div>
            <div class="sp_info">
              <van-image width="20" height="20" :src="item.courseUrl" round />
              <span>{{ item.spcolumnName }}</span>
            </div>
            <div class="desc">
              <van-rate v-model="item.level" readonly size="10px" color="red" />
              <span
                >{{ item.chapterCount }}节 · {{ item.viewNum }}观看 ·
                {{ item.courseCommentNum }}评论</span
              >
            </div>
            <div class="footer">
              <span class="price">{{
                item.price > 0 ? item.price + "金石" : "免费"
              }}</span>
              <span class="vip">
                <i class="iconfont icon-VIP1"></i>
                {{
                  item.vipPrice > 0 ? item.vipPrice + "金石" : "VIP免费"
                }}</span
              >
            </div>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>



<script >
import { defineComponent, onMounted, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import { getCourslist } from "../../api/crouse";
export default defineComponent({
  setup() {
    const router = useRouter();
    const handleHome = () => {
      router.push("/my");
    };

    const list = ref([]);
    const loading = ref(false);
    const finished = ref(false);

    const query = reactive({
      pageIndex: 0,
      pageSize: 10,
      marketId: "",
      ruleState: 1, //	1-全部，2-免费，3-收费，4-会员免费
    });

    // 加载
    const onLoad = async () => {
      query.pageIndex++;
      const res = await getCourslist(query);
      if (res) {
        list.value = list.value.concat(res);
        loading.value = false;
        if (res.length <= 0) {
          finished.value = true;
        } else {
          finished.value = false;
        }
      }
    };

    const handleChaneType = (v) => {
      query.marketId = v;
      query.pageIndex = 0;
      list.value = [];
      onLoad();
    };

    const handleClick = (item) => {
      router.push({
        path: "/crousedetail",
        query: {
          courseId: item.courseId,
        },
      });
    };
    return {
      loading,
      finished,
      query,
      list,
      onLoad,
      handleHome,
      handleClick,
      handleChaneType,
    };
  },
});
</script>


<style lang="scss" scoped>
.article_page {
  .nav_right {
    color: #fff;
    display: flex;
    span {
      line-height: 50px;
      margin-right: 5px;
    }
  }
  .list {
    padding: 20px 10px;
    .list_item {
      height: 100px;
      display: flex;
      flex-direction: row;
      margin-bottom: 10px;
      padding-bottom: 10px;
      border-bottom: 1px solid #f1ecec;
      .left {
        width: 120px;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .right {
        width: calc(100% - 120px);
        font-size: 12px;
        display: flex;
        flex-direction: column;
        padding: 5px;
        .name {
          font-size: 14px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .sp_info {
          height: 20px;
          line-height: 20px;
          display: flex;
          align-items: center;
          margin: 5px 0;
          span {
            margin-left: 5px;
            color: #afadad;
          }
        }
        .desc {
          height: 15px;
          line-height: 15px;
          display: flex;
          align-items: center;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          span {
            margin-left: 10px;
            color: #777676;
            position: relative;
            top: 1px;
          }
        }
        .footer {
          font-size: 12px;
          margin-top: 10px;
          display: flex;
          align-items: center;
          .price {
            color: #c96819;
          }
          .vip {
            display: flex;
            color: red;
            align-items: center;
            margin-left: 10px;
            i {
              margin-right: 5px;
              font-size: 16px;
            }
          }
        }
      }
    }
  }
}

.my-swipe .van-swipe-item {
  overflow: hidden;
  height: 200px;
  img {
    width: 100%;
    height: 100%;
  }
}

.van-swipe {
  overflow: hidden;
  width: 95%;
  margin: 10px auto;
  border-radius: 8px;
  box-shadow: 0 12px 10px rgba(80, 79, 79, 0.247);
}
::v-deep(.van-sticky--fixed) {
  background: #ffffff;
}
</style>